import java.util.Stack;

public class Tokens {
    class Solution {
        public int evalRPN(String[] tokens) {
            Stack<Integer> stack = new Stack<>();
            for (int i = 0; i < tokens.length; i++){
                String val = tokens[i];
                if (isOperation(val) == false){
                    stack.push(Integer.parseInt(val));
                }else{
                    int num2 = stack.pop();
                    int num1 = stack.pop();
                    switch(val){
                        case "+":
                            stack.push(num1 + num2);
                            break;
                        case "-":
                            stack.push(num1 - num2);
                            break;
                        case "*":
                            stack.push(num1 * num2);
                            break;
                        case "/":
                            stack.push(num1 / num2);
                            break;
                    }
                }
            }
            return stack.pop();
        }
        private boolean isOperation(String x){
            if (x.equals("+") || x.equals("-") || x.equals("*") || x.equals("/") ){
                return true;
            }else
                return false;
        }
    }
}
